#include <stdio.h>
#include <semaphore.h>
#include <pthread.h>

void* fun(void*);

int data;
sem_t sem;

int main(int argc,char* argv[]){
  sem_init(&sem,0,0);
  pthread_t tid;
  
  pthread_create(&tid,NULL,fun,NULL);

  while(1){
    printf("please input:");
    scanf("%d",&data);
    sem_post(&sem);
    if(data == -1)
      break;
  }

  sem_destroy(&sem);
  pthread_exit(NULL);
}

void* fun(void* daa){

  while(1){
    sem_wait(&sem);
    printf("read is %d\n",data);
    if(data == -1)
      break;

  }
  pthread_exit(NULL);
}
